package com.soonzlab.englishlearning.client;

import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Portlet;

public class PortalLayout extends HLayout {  
    public PortalLayout(int numColumns) {  
        setMembersMargin(6);  
        for (int i = 0; i < numColumns; i++) {  
            addMember(new PortalColumn());  
        }  
    }  

    public PortalColumn addPortlet(com.soonzlab.englishlearning.client.Portlet portletOriginal) {  
        // find the column with the fewest portlets  
        int fewestPortlets = Integer.MAX_VALUE;  
        PortalColumn fewestPortletsColumn = null;  
        for (int i = 0; i < getMembers().length; i++) {  
            int numPortlets = ((PortalColumn) getMember(i)).getMembers().length;  
            if (numPortlets < fewestPortlets) {  
                fewestPortlets = numPortlets;  
                fewestPortletsColumn = (PortalColumn) getMember(i);  
            }  
        }  
        fewestPortletsColumn.addMember(portletOriginal);  
        return fewestPortletsColumn;  
    }  
}
